package com.xczl.book.action;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xczl.book.entity.Book;

@Controller("bookBookAction")
@RequestMapping("book/admin/book")
public class BookAction {
	
	@RequestMapping("list.htm")
	public String index(ModelMap model) {

		List<Book> list = new ArrayList<Book>();

		list.add(createBook("MySql开发指南", BigDecimal.valueOf(50.00), 20, 10));
		list.add(createBook("JAVA开发指南", BigDecimal.valueOf(50.00), 20, 10));
		list.add(createBook("PHP开发指南", BigDecimal.valueOf(50.00), 20, 10));
		list.add(createBook("JAVASCRIPT开发指南", BigDecimal.valueOf(50.00), 20, 10));
		list.add(createBook("红帽", BigDecimal.valueOf(50.00), 20, 10));
		list.add(createBook("大数据", BigDecimal.valueOf(50.00), 20, 10));
		

		model.addAttribute("list", list);
		return "book/admin/book/list";
	}

	/***
	 * 模拟创建图书
	 * 
	 * @param name
	 * @param price
	 * @param total
	 * @param num
	 * @return
	 */
	private Book createBook(String name, BigDecimal price, int total, int num) {
		Book book = new Book();
		book.setBookName(name);
		book.setPrice(price);
		book.setTotalNumber(total);
		book.setActualQuantity(num);
		book.setCreateTime(new Date());
		return book;
	}
	
	/*@RequestMapping("add.htm")
	public String addBook(Book book) {
		return "book/admin/book/add";
	}*/
}
